package base;
/**
 * this class creates a "FolderItem",
 * which is the super class of "file" and "folder"
 * @author zjy
 * @version 1.2.0
 */
public class FolderItem {
    /**
     * your folder/file's name
     */
    private String name;
    /**
     * construct method,
     * feel free to delete the println function
     */
    public FolderItem(String initialName) {
        if(!setName(initialName)) {
            System.out.println("Invalid file/folder name!");
            return;
        }
        name = initialName;
    }

    /**
     * get item's name
     * @return name
     */
    public String getName() {
        return name;
    }
    /**
     * set item's name while checking if it's legal
     * @return true/false
     */
    public boolean setName(String newName) {
        String bannedChar = "/\\:*\"<>|";
        for ( int i = 0; i < bannedChar.length(); i++) {
            //System.out.println(bannedChar.charAt(i));
            for( int j = 0; j < newName.length(); j++) {
                if(bannedChar.charAt(i) == newName.charAt(j))
                    return false;
            }
        }
        return true;
    }
}
